#-*- coding:utf8 -*-
import types
import re

def IsNumber(varObj):
    return type(varObj) is types.IntType
 
def IsString(varObj):
    return type(varObj) is types.StringType

def IsFloat(varObj):
    return type(varObj) is types.FloatType
 
def IsDict(varObj):
    return type(varObj) is types.DictType
 
def IsTuple(varObj):
    return type(varObj) is types.TupleType
 
def IsList(varObj):
    return type(varObj) is types.ListType
 
def IsBoolean(varObj):
    return type(varObj) is types.BooleanType
 
def IsCurrency(varObj):
    if IsFloat(varObj) and IsNumber(varObj):
        if varObj > 0:
            return True
        else:
            return False
    return True
 
def IsEmpty(varObj):
    if len(varObj) == 0:
        return True
    return False
 
def IsNone(varObj):
    return type(varObj) is types.NoneType

def IsDate(varObj):
    if len(varObj) == 10:
        rule = '(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)$/'
        match = re.match( rule , varObj )
        if match:
            return True
        return False
    return False
 
def IsEmail(varObj):
    rule = '[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$'
    match = re.match( rule , varObj )
    if match:
        return True
    return False
 
def IsChineseCharString(varObj):
    for x in varObj:
        if (x >= u"\u4e00" and x <= u"\u9fa5") or (x >= u'\u0041' and x <= u'\u005a') or (x >= u'\u0061' and x <= u'\u007a'):
            continue
        else:
            return False
    return True
 
def IsChineseChar(varObj):
    if varObj[0] > chr(127):
        return True
    return False
 
def IsLegalAccounts(varObj):
    rule = '[a-zA-Z][a-zA-Z0-9_]{3,15}$'
    match = re.match( rule , varObj )
    if match:
        return True
    return False
 
def IsIpAddr(varObj):
    rule = '\d+\.\d+\.\d+\.\d+'
    match = re.match( rule , varObj )
    if match:
        return True
    return False

def IsName(varObj):
    i = 0
    for x in varObj:
        if (x >= u"\u4e00" and x <= u"\u9fa5") or (x >= u'\u0041' and x <= u'\u005a') or (x >= u'\u0061' and x <= u'\u007a'):
            i += 2
        elif (x >= 'a' and x <= 'z') or (x >= 'A' and x <= 'Z'):
            i += 1
        else:
            return False
    if i < 4 or i > 14:
        return False
    else:
        return True